package xhwl.hmo.mall.utils;

import android.content.Context;
import android.util.Log;

import cn.jpush.android.api.JPushInterface;

public class JPushMgr {
	private static JPushMgr instance;
	private JPushMgr(){
		
	}
	public static JPushMgr getInstance(){
		if(instance==null){
			instance=new JPushMgr();
		}
		return instance;
	}
	/**注册极光推送s
	 * @param context
	 * @param callback
	 */
	public void registJPushId(Context context,RegistJpushCallback callback){
		String jpushId=SpUtil.getString(SpUtil.JPUSH_ID,"");
		if(!StringUtil.isEmpty(jpushId))
		{
			callback.onResult(true, jpushId);
		}
		if(AppUtil.iskNetAvailable(context)){
			String rid = JPushInterface.getRegistrationID(context.getApplicationContext());
			if (!StringUtil.isEmpty(rid)) {
				SpUtil.putString(SpUtil.JPUSH_ID,rid);
				Log.e("jpush", "registJPushId="+rid);
				callback.onResult(true, rid);
			} else {
				Log.e("jpush", "registJPushId fail");
				callback.onResult(false, "registJPushId fail");
			}
		}
	}
	public interface RegistJpushCallback {
		void onResult(boolean result, String msg);
	}
}
